package com.interceptor;

import com.entity.User;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Login implements HandlerInterceptor {

    //登陆了，可以访问其他页面
    //没有登陆,不可以访问,只能查看首页(登录注册)
    public class LoginHandlerInterceptor implements HandlerInterceptor {
        @Override
        public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
            //登陆成功之后，获取用户的session
             User loginUser = (User)request.getSession().getAttribute("User");
             if (loginUser==null){
            // 未登录
                 response.sendRedirect(request.getContextPath()+"/pages/front/front_index.html");
                 return false;
             }else {
                 return true;
             }
        }
    }
}
